<?php

namespace App\Http\Controllers\web;

use App\Http\Controllers\Controller;
use App\Http\Service\web\Siberian;
use App\Repository\RepositoryInterface\MemberInterface;
use Illuminate\Http\Request;

//会员类控制器
class MemberController extends Controller
{
    //
    protected $member;

    public function __construct(MemberInterface $member){
        $this->member = $member;
    }

    public function list(){
        $this->member->list();
    }

    /**
     * 会员类型
     * @return false|string
     */
    public function memberType(){
        $data = $this->member->memberType();
        return json_encode(['msg'=>'会员类型','code'=>20000,'data'=>$data]);
    }

    /**
     * 会员类型添加
     * @param Request $request
     * @return false|string
     */
    public function memberTypeAdd(Request $request){
        $data = $request->post();
        $array = $this->member->memberTypeAdd($data);
        return json_encode(['msg'=>'会员类型添加成功','code'=>20000,'data'=>$array]);
    }

    /**
     * 会员类型删除
     * @param Request $request
     * @return false|string
     */
    public function memberTypeDel(Request $request){
        $id = $request->input('id');
        $res = $this->member->memberTypeDel($id);
        return json_encode(['msg'=>'会员类型删除成功','code'=>20000,'data'=>$res]);
    }

    /**
     * 会员开启状态
     * @param Request $request
     * @return false|string
     */
    public function memberTypeBegin(Request $request){
        $id = $request->input('id');
        $res = $this->member->memberTypeBegin($id);
        return json_encode(['msg'=>'会员类型开启成功','code'=>20000,'data'=>$res]);
    }


    /**
     * 会员权益
     * @return false|string
     */
    public function memberEquity(){
        $data = $this->member->memberEquity();
        return json_encode(['msg'=>'会员权益','code'=>20000,'data'=>$data]);
    }


    /**
     * 卡密会员
     * @return false|string
     */
    public function memberSiberian(){
        $data = $this->member->SiberianMember();
        return json_encode(['msg'=>'卡密会员','code'=>20000,'data'=>$data]);
    }

    /**
     * 生成卡密
     * @return string
     */
    public function SiberianCreate(): string
    {
        return Siberian::siberian();
    }

    /**
     * 批量添加卡密会员
     * @param Request $request
     * @return false|string
     */
    public function memberSiberianAdd(Request $request){
        $data = $request->all();
        $data['use_number']=0;
        $this->member->memberSiberianAdd($data);
        $this->member->SiberianCreate($data);
        return json_encode(['msg'=>'卡密会员添加','code'=>20000,'data'=>$data]);
    }

    /**
     * 卡密会员搜索
     * @param Request $request
     * @return false|string
     */
    public function memberSiberianSearch(Request $request){
        $keyword = $request->input('keyword');
        $data = $this->member->memberSiberianSearch($keyword);
        return json_encode(['msg'=>'卡密会员搜索','code'=>20000,'data'=>$data]);
    }

    /**
     * 会员记录
     * @return false|string
     */
    public function memberRecord(){
        $data = $this->member->memberRecord();
        return json_encode(['msg'=>'会员记录','code'=>20000,'data'=>$data]);
    }
}
